package sw.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import sw.entity.Classes;
import sw.repo.ClassesRepository;

@Controller
public class classesController {

	@Autowired
	private ClassesRepository clasRepo;
	
	@GetMapping("/classM")
	public String showM(Model model){
		Iterable<Classes> classes = clasRepo.findAll();
		model.addAttribute("classes", classes);
		return "/classM";
	}
	
	@PostMapping("/addBookClas")
	public String addClas(Classes clas){
		clasRepo.save(clas);
		return "redirect:/classM";
	}
	
	@GetMapping("/delC/{id}")
	public String delC(@PathVariable Long id){
		clasRepo.delete(id);
		
		return "redirect:/classM";
	}
}
